
package com.rt.schedulenew.web;

import java.util.List;

import com.github.pagehelper.Page;
import com.rt.schedulebase.dto.DictTerminalDto;
import com.rt.schedulenew.utils.global.PageVO;
import com.github.pagehelper.PageHelper;
import org.springframework.web.bind.annotation.PostMapping;
import com.rt.schedulenew.utils.global.JsonResultUtil;
import com.rt.schedulenew.utils.base.RequestUtil;
import org.apache.commons.lang3.StringUtils;
import com.rt.schedulenew.utils.global.JsonResult;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import com.rt.schedulenew.api.IDictTerminalService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 自助机设置相关接口
 */
@RestController
@RequestMapping({"/self"})
public class SelfController {
    @Autowired
    private IDictTerminalService dictTerminalService;

    @PostMapping({"/selfDeviceInfo"})
    public JsonResult getSelfDeviceInfo(@RequestBody DictTerminalDto dto, HttpServletRequest req) {
        if (StringUtils.isBlank(dto.getIpAddress())) {
            dto.setIpAddress(RequestUtil.getRemoteAddr(req));
        }
        return JsonResultUtil.success("成功", dictTerminalService.getSelfDeviceInfo(dto));
    }

    /**
     * 自助机设置列表获取
     *
     * @param dto
     * @return
     */
    @PostMapping({"/list"})
    public JsonResult getSelfDeviceList(@RequestBody DictTerminalDto dto) {
        Page<?> page = PageHelper.startPage(dto.getPageNo(), dto.getPageSize());
        List<DictTerminalDto> list = dictTerminalService.selectList(dto);
        PageVO pageVO = new PageVO();
        pageVO.setPageNo(dto.getPageNo());
        pageVO.setPageSize(dto.getPageSize());
        pageVO.setTotal(page.getTotal());
        pageVO.setPages(page.getPages());
        return JsonResultUtil.success("成功", list, pageVO);
    }

    @PostMapping({"/save"})
    public JsonResult saveSelfDevice(@RequestBody DictTerminalDto dto) {
        JsonResult jsonResult = dictTerminalService.saveSelfDevice(dto);
        return jsonResult;
    }

    /***
     * 修改自助机相关配置信息
     * @param dto 配置信息
     * @return jsonresult
     */
    @PostMapping({"/edit"})
    public JsonResult editSelfDevice(@RequestBody DictTerminalDto dto) {
        JsonResult jsonResult = dictTerminalService.editSelfDevice(dto);
        return jsonResult;
    }

    @PostMapping({"/delete"})
    public JsonResult deleteSelfDevice(@RequestBody DictTerminalDto dto) {
        JsonResult jsonResult = dictTerminalService.deleteSelfDevice(dto);
        return jsonResult;
    }
}
